<!-- <template>
    <div class="add">
        <el-tabs v-model="activeName">
            <el-tab-pane name="first">
                <span slot="label">
                    <i class="el-icon-circle-plus"></i>添加考试
                </span>
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="试卷名称">
                        <el-input v-model="form.source" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="介绍">
                        <el-input v-model="form.description" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="考试日期">
                        <el-date-picker
                            placeholder="选择日期"
                            v-model="form.examDate"
                            style="width: 30%;"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="持续时间">
                        <el-input v-model="form.totalTime" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="考试类型">
                        <el-input v-model="form.type" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="考生提示">
                        <el-input type="textarea" v-model="form.tips" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit()">立即创建</el-button>
                        <el-button type="text" @click="cancel()">取消</el-button>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane name="second">
                <span slot="label">
                    <i class="iconfont icon-daoru-tianchong"></i>详细设置
                </span>
                <el-form ref="form1" :model="info" label-width="80px">
                    <el-form-item label="试卷类型">
                        <el-select v-model="info.type" placeholder="请选择试卷科目">
                            <el-option
                                v-for="item in typeOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="简单题百分比">
                        <el-input v-model="info.simple" placeholder style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="中档题百分比">
                        <el-input v-model="info.normal" placeholder style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="困难题百分比">
                        <el-input v-model="info.diff" placeholder style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="客观题数量">
                        <el-input v-model="info.num1" placeholder="请输入客观题数量" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="问答题题数量">
                        <el-input v-model="info.num2" placeholder="请输入问答题数量" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="材料题数量">
                        <el-input v-model="info.num3" placeholder="请输入材料题数量" style="width: 30%;"></el-input>
                    </el-form-item>
                    <el-form-item label="考试范围">
                        <el-input v-model="info.theme" placeholder="请输入考试范围" style="width: 30%;"></el-input>
                    </el-form-item>
                    <div class="button-container">
                        <el-button type="primary" @click="add()">确 定</el-button>
                        <el-button @click="back()">取 消</el-button>
                    </div>
                </el-form>
            </el-tab-pane>
        </el-tabs>
    </div>
</template> -->
<template>
    <div class="add">
        <el-row :gutter="30">
            <el-col :span="8">
                <el-form ref="form" :model="DTA.form" label-width="60px">
                    <el-form-item label="试卷名称" :label-style="{ fontSize: '8px' }">
                        <el-input v-model="DTA.form.source" style="width: 70%;"></el-input>
                    </el-form-item>
                    <el-form-item label="介绍">
                        <el-input v-model="DTA.form.description" style="width: 70%;" ></el-input>
                    </el-form-item>
                    <el-form-item label="考试日期">
                        <el-date-picker
                            placeholder="选择日期"
                            v-model="DTA.form.examDate"
                            style="width: 70%;"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="持续时间（min）">
                        <el-input v-model="DTA.form.totalTime" style="width: 70%;" ></el-input>
                    </el-form-item>
                    <el-form-item label="考生提示">
                        <el-input type="textarea" v-model="DTA.form.tips" style="width: 70%;"></el-input>
                    </el-form-item>
                </el-form>
            </el-col>
            <el-col :span="8">
              <el-form>
                <el-form-item label="试卷类型">
                    <el-select v-model="DTA.info.type" placeholder="请选择试卷科目" style="width: 70%;">
                        <el-option
                            v-for="item in typeOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="简单题占比">
                    <el-input v-model="DTA.info.simple" placeholder style="width: 70%;" ></el-input>
                </el-form-item>
                <el-form-item label="中档题占比">
                    <el-input v-model="DTA.info.normal" placeholder style="width: 70%;"></el-input>
                </el-form-item>
                <el-form-item label="困难题占比">
                    <el-input v-model="DTA.info.diff" placeholder style="width: 70%;"></el-input>
                </el-form-item>
                <el-form-item label="客观题数量">
                    <el-input v-model="DTA.info.num1" placeholder="请输入客观题数量" style="width: 70%;"></el-input>
                </el-form-item>
                <el-form-item label="材料题数量">
                    <el-input v-model="DTA.info.num3" placeholder="请输入材料题数量" style="width: 70%;" ></el-input>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="8">
              <!-- <el-form>
                <el-form-item label="考试范围" style="margin-bottom: 20px;">
                    <el-input v-model="DTA.info.theme" placeholder="请输入考试范围" style="width: 70%;"></el-input>
                </el-form-item>
                <el-form-item style="margin-bottom: 20px;">
        <el-button type="primary" @click="onSubmit()">立即创建</el-button>
        <el-button type="text" @click="cancel()">取消</el-button>
      </el-form-item>
              </el-form> -->
              <el-form>
    <el-form-item 
      label="试卷知识点" 
      style="margin-bottom: 400px;">
      <el-input 
        v-model="DTA.info.theme" 
        placeholder="请输入考试范围" 
        style="width: 70%;">
      </el-input>
    </el-form-item>
    <el-form-item style="margin-top: 360px;">
      <el-button type="primary" @click="onSubmit()">立即创建</el-button>
      <el-button type="text" @click="cancel()">取消</el-button>
    </el-form-item>
  </el-form>
            </el-col>
        </el-row>
    </div>
</template>
<script>
export default {
    data() {
        return {
            DTA: {
                form: { //表单数据初始化
        source: '',
        description: '',
        institute: '',
        major: '',
        grade: '',
        examDate: '',
        totalTime: '30',
        totalScore: '',
        type: '',
        tips: '',
        paperId: '',
      },
                info: {
                    type: '',
                    simple: '0.7',
                    normal: '0.2',
                    diff: '0.1',
                    num1: '1',
                    num2: '0',
                    num3: '1',
                    theme: '商鞅变法'
                }
            },
            activeName: "first",
            typeOptions: [
                { value: "历史", label: "历史" },
                { value: "地理", label: "地理" },
                { value: "政治", label: "政治" },
            ],
        };
    },
    // created() {
    //   this.getParams()
    // },
    methods: {
        formatTime(date) {
            //日期格式化
            let year = date.getFullYear();
            let month =
                date.getMonth() + 1 < 10
                    ? "0" + (date.getMonth() + 1)
                    : date.getMonth() + 1;
            let day =
                date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            let hours =
                date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
            let minutes =
                date.getMinutes() < 10
                    ? "0" + date.getMinutes()
                    : date.getMinutes();
            let seconds =
                date.getSeconds() < 10
                    ? "0" + date.getSeconds()
                    : date.getSeconds();
            // 拼接
            return (
                year +
                "-" +
                month +
                "-" +
                day +
                " " +
                hours +
                ":" +
                minutes +
                ":" +
                seconds
            );
        },
        onSubmit() {
            if(this.DTA.form.examDate!='')
            {let examDate = this.formatTime(this.DTA.form.examDate);
            this.DTA.form.examDate = examDate.substr(0, 10);}
            this.$axios(`/api/examManagePaperId`).then((res) => {
                this.DTA.form.paperId = res.data.data.paperId + 1; //实现paperId自增1
                this.$axios({
                    url: "/api/exam",
                    method: "post",
                    data: {
                        ...this.DTA,
                    },
                }).then((res) => {
                    if (res.data.code == 200) {
                        this.$confirm('试卷添加成功，是否继续操作？', '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'success'
                        }).then(() => {
                            // 用户点击"确定"后的逻辑
                            console.log('确认');
                        }).catch(() => {
                            // 用户点击"取消"后的逻辑
                            console.log('取消');
                        });
                    }
                });
            });
        },
        cancel() {
            //取消按钮
            this.DTA.form = {};
            this.DTA.info = {};
        },
        back() {},

        // add() {
        //     this.$axios({
        //         url: "/api/exam/set",
        //         method: "post",
        //         data: {
        //             ...this.DTA,
        //         },
        //     }).then((res) => {
        //         if (res.data.code == 200) {
        //             this.$message({
        //                 //成功修改提示
        //                 message: "更新成功",
        //                 type: "success",
        //             });
        //         }
        //     });
        // },
    },
};
</script>

<style lang="less" scoped>
.button-container {
    text-align: center;
}
.add {
    margin: 0px 40px;
}

</style>